﻿<!--Write a function that counts how many times given number appears in given array. 
Write a test function to check if the function is working correctly.

-->

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Count Occurences</title>
    <link href="styles/js-console.css" rel="stylesheet" />
</head>
<body>
    <div id="js-console"></div>
    
    <script src="scripts/js-console.js"></script>
    <script>
        var testArr = new Array(2, 5, 6, 7, 2, 2, 6);
        var numToSearch = 2;
        var i = 0
        printArray(testArr);
        countOccurences(testArr, numToSearch);

        function countOccurences(testArr, numToSearch) {
            var counter = 0;
            for (i = 0; i < testArr.length; i++) {
                if (testArr[i] === numToSearch) {
                    counter++;
                }
            }
            jsConsole.writeLine("The number " + numToSearch + " occurs " + counter + " times.");
        }
        function printArray(testArr) {
            jsConsole.writeLine("The array is: " + testArr.join(","));
        }
    </script>
</body>
</html>